Skip to content

Assignable TemplateLiteral of Intersection Type of Primitive and {} to Primitive String#61174

Closed
horita-yuya wants to merge 1 commit intomicrosoft:mainfrom
horita-yuya:main
Closed

Assignable TemplateLiteral of Intersection Type of Primitive and {} to Primitive String#61174
horita-yuya wants to merge 1 commit intomicrosoft:mainfrom
horita-yuya:main

Conversation

@horita-yuya
Copy link

Fixes #60990 (partially)

We can use a technique called branded types by defining a type as primitive & { brand: "branded" }.

This has the benefit of allowing you to handle the target primitive type more constrainedly. For example, with 1 & { brand: "branded" } type, it can only be used in a narrower context than the literal type 1.

The relationship between the types is:

1 & { brand: "branded" } < 1 < number

In other words, 1 & { brand: "branded" } can be assigned to a 1 type, and 1 can be assigned to a number type.

Wouldn't it be more natural to handle Template Literals similarly?

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Feb 13, 2025
@horita-yuya
Copy link
Author

@microsoft-github-policy-service agree

@horita-yuya horita-yuya changed the title Treat primitive and object Intersection Type inside TemplateLiteral as primitive Assignable TemplateLiteral of Intersection Type of Primitive and {} to Primitive Feb 15, 2025
@horita-yuya horita-yuya changed the title Assignable TemplateLiteral of Intersection Type of Primitive and {} to Primitive Assignable TemplateLiteral of Intersection Type of Primitive and {} to Primitive String Feb 15, 2025
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Branded string literals revert to string in some cases

3 participants